import 'package:board_datetime_picker/board_datetime_picker.dart';
import 'package:catguard/global/global_data.dart';
import 'package:catguard/views/add_record_Image_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../config/config.dart';
import '../../../views/common_widget.dart';
import '../../../views/dialog_manager.dart';
import 'logic.dart';

class AddWeightPage extends StatelessWidget {
  AddWeightPage({super.key});

  final logic = Get.find<AddWeightLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg,
      resizeToAvoidBottomInset: false,
      body: Column(
        children: [
          CommonWidget.commonAppBar("记录体重"),
          //菜单
          Container(
            width: double.infinity,
            margin: EdgeInsets.only(top: 30.w, left: 35.w, right: 35.w),
            padding: EdgeInsets.symmetric(horizontal: 35.w, vertical: 4.w),
            decoration: BoxDecoration(
              color: Config.colorBg2,
              borderRadius: BorderRadius.circular(Config.roundBig.w),
            ),
            child: ListView(
              padding: const EdgeInsets.symmetric(vertical: 0),
              scrollDirection: Axis.vertical,
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              children: [
                menuItem("记录宠物", () {
                  DialogManager.showBottomMenu(context, List.generate(global.pets.length, (index){
                    return global.pets[index]['name'];
                  }), global.currentPet.value, (index){
                    global.currentPet.value=index;
                  });
                }, subTitle: "请选择"),
                CommonWidget.commonDivider(),
                menuItem("记录时间", () async {
                  // final result = await showBoardDateTimePicker(
                  //   context: context,
                  //   pickerType: DateTimePickerType.date,
                  // );
                  DialogManager.showBottomDatePop(context, (str) {
                    EasyLoading.showToast('选择的时间=$str');
                  });
                }, subTitle: "请选择"),
                CommonWidget.commonDivider(),
                menuItem("记录体重", () {
                  DialogManager.showEditDialog("宠物体重(KG)", (text) {});
                }, subTitle: "请输入"),
              ],
            ),
          ),

          //多图选择
          AddRecordImageWidget(),

          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                CommonWidget.commonButton("保存", () {}, width: 620.w, radius: 50.w),
                SizedBox(height: 110.w),
              ],
            ),
          ),
        ],
      ),
    );
  }

  menuItem(String title, Function() onTap, {String? subTitle}) {
    return InkWell(
      onTap: onTap,
      child: SizedBox(
        height: 114.w,
        child: Row(
          children: [
            Text(
              title,
              style: TextStyle(color: Config.colorText1, fontSize: Config.textSizeContent.sp),
            ),
            Expanded(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Visibility(
                    visible: subTitle != null,
                    child: Text(
                      subTitle ?? "",
                      style:
                          TextStyle(color: Config.colorText3, fontSize: Config.textSizeContent.sp),
                    ),
                  ),
                  SizedBox(width: 10.w),
                  Icon(
                    Icons.arrow_forward_ios_rounded,
                    color: Config.colorText3.withOpacity(0.7),
                    size: 32.w,
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
